package com.ruoyi.system.service.impl;
import java.util.List;

import com.ruoyi.common.enums.DelFlagStatus;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysChannelOutMapper;
import com.ruoyi.system.domain.SysChannelOut;
import com.ruoyi.system.service.ISysChannelOutService;
import com.ruoyi.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 出金通道Service业务层处理
 *
 * @author Ericcc
 * @date 2021-02-13
 */
@Service
public class SysChannelOutServiceImpl implements ISysChannelOutService
{
    @Autowired
    private SysChannelOutMapper sysChannelOutMapper;

    /**
     * 查询出金通道
     *
     * @param channelOutId 出金通道ID
     * @return 出金通道
     */
    @Override
    public SysChannelOut selectSysChannelOutById(Long channelOutId)
    {
        return sysChannelOutMapper.selectSysChannelOutById(channelOutId);
    }

    /**
     * 查询出金通道列表
     *
     * @param sysChannelOut 出金通道
     * @return 出金通道
     */
    @Override
    public List<SysChannelOut> selectSysChannelOutList(SysChannelOut sysChannelOut)
    {
        return sysChannelOutMapper.selectSysChannelOutList(sysChannelOut);
    }

    /**
     * 新增出金通道
     *
     * @param sysChannelOut 出金通道
     * @return 结果
     */
    @Override
    @Transactional
    public int insertSysChannelOut(SysChannelOut sysChannelOut)
    {
        int number = 3000;
        SysChannelOut checkNumber = sysChannelOutMapper.selectOneSysChannelOut();
        if (checkNumber != null){
            number =  checkNumber.getChannelOutCode() + 1;
        }
        sysChannelOut.setChannelOutCode(number);
        sysChannelOut.setCreateTime(DateUtils.getNowDate());
        sysChannelOut.setDelFlag(DelFlagStatus.LIVE.getCode());
        return sysChannelOutMapper.insertSysChannelOut(sysChannelOut);
    }

    /**
     * 修改出金通道
     *
     * @param sysChannelOut 出金通道
     * @return 结果
     */
    @Override
    @Transactional
    public int updateSysChannelOut(SysChannelOut sysChannelOut)
    {
        sysChannelOut.setUpdateTime(DateUtils.getNowDate());
        return sysChannelOutMapper.updateSysChannelOut(sysChannelOut);
    }

    /**
     * 删除出金通道对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteSysChannelOutByIds(String ids)
    {
        return sysChannelOutMapper.deleteSysChannelOutByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除出金通道信息
     *
     * @param channelOutId 出金通道ID
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteSysChannelOutById(Long channelOutId)
    {
        return sysChannelOutMapper.deleteSysChannelOutById(channelOutId);
    }

    @Override
    public List<SysChannelOut> selectByUser(Long userId) {
        return sysChannelOutMapper.selectSysChannelOutList(new SysChannelOut());
    }
}